package persistence

import (
	"gorm.io/gorm"
	"tools.hezhuyun/checker/domain/entity"
)

type FileRepo struct {
	db *gorm.DB
}

func NewFileRepository(db *gorm.DB) *FileRepo {
	return &FileRepo{db}
}

func (repo *FileRepo) GetFile(id uint64) (*entity.File, error) {
	var file *entity.File
	result := repo.db.Where("id = ?", id).First(&file)
	return file, result.Error
}

func (repo *FileRepo) GetFilesByInnerCode(code string) ([]*entity.File, error) {
	var files []*entity.File
	result := repo.db.Where("CatalogInnerCode like ?", code+"%").Find(&files)
	return files, result.Error
}

func (repo *FileRepo) CheckFileIsExist(file *entity.File) bool {
	return repo.CheckFileIsExist(file)
}
